package com.pokermind.dse.tcp.client.interactive;

import java.util.HashMap;
import java.util.Map;

/**
 * 预设牌局脚本 - 用于AI决策对比测试
 * 
 * @author PokerMind Interactive Client
 */
public class ScenarioScript {
    
    /**
     * 牌局脚本：6人完整牌局
     * 
     * 正确的牌局流程：
     * 1. 创建牌局，SB/BB已下盲注
     * 2. Preflop从UTG开始，依次UTG→MP→CO→BTN→SB→BB
     * 3. Postflop从SB开始，依次SB→BB→其他在局玩家
     */
    public static class ClassicBTNvsBB {
        
        // 底牌配置
        private static final Map<String, String> HOLE_CARDS = new HashMap<>() {{
            put("player_sb", "2c 7d");    // SB 垃圾牌
            put("player_bb", "Qh Jh");    // BB 同花连牌
            put("player_utg", "9s 8s");   // UTG 中等牌
            put("player_mp", "Kd Qd");    // MP 好牌但位置不好
            put("player_co", "Tc 9c");    // CO 中等牌
            put("player_btn", "As Ks");   // BTN 强牌
        }};
        
        // 公共牌
        private static final Map<String, String> BOARD_CARDS = new HashMap<>() {{
            put("flop", "Ah 9h 3c");
            put("turn", "7d");
            put("river", "Kh");
        }};
        
        // 预设行动脚本（简化：只用位置作为key，按顺序执行）
        private static final Map<String, ScriptAction> ACTIONS = new HashMap<>() {{
            // Preflop顺序：UTG → MP → CO → BTN → SB → BB
            put("preflop_UTG", new ScriptAction("fold", 0, "位置差，牌力一般，弃牌"));
            put("preflop_MP", new ScriptAction("fold", 0, "虽然牌不错，但位置不好，弃牌"));
            put("preflop_CO", new ScriptAction("fold", 0, "中等牌，位置一般，弃牌"));
            put("preflop_BTN", new ScriptAction("raise", 700, "强牌+位置优势，加注隔离"));
            put("preflop_SB", new ScriptAction("fold", 0, "垃圾牌，面对加注弃牌"));
            put("preflop_BB", new ScriptAction("call", 500, "同花连牌，有潜力，跟注看翻牌"));
            
            // Flop顺序：BB → BTN（只剩这两人）
            put("flop_BB", new ScriptAction("check", 0, "有听牌，先check诱导"));
            put("flop_BTN", new ScriptAction("raise", 800, "顶对顶踢脚，持续下注"));
            put("flop_BB_2", new ScriptAction("call", 800, "9outs坚果同花听牌，pot odds合理"));
            
            // Turn顺序：BB → BTN
            put("turn_BB", new ScriptAction("check", 0, "没中，继续check"));
            put("turn_BTN", new ScriptAction("raise", 1500, "持续施压"));
            put("turn_BB_2", new ScriptAction("call", 1500, "pot大，隐含赔率好"));
            
            // River顺序：BB → BTN
            put("river_BB", new ScriptAction("raise", 3000, "完成坚果同花，价值下注"));
            put("river_BTN", new ScriptAction("call", 3000, "两对，很难弃牌"));
        }};
        
        public static String getHoleCards(String userId) {
            return HOLE_CARDS.getOrDefault(userId, "");
        }
        
        public static String getBoardCards(String street) {
            return BOARD_CARDS.getOrDefault(street, "");
        }
        
        /**
         * 获取行动（简化版）
         * @param street 街道
         * @param position 位置
         * @param isSecondAction 是否是第二次行动（例如BB check后又面对下注）
         */
        public static ScriptAction getAction(String street, String position, boolean isSecondAction) {
            String key = street + "_" + position + (isSecondAction ? "_2" : "");
            ScriptAction action = ACTIONS.get(key);
            
            // 如果没有第二次行动的脚本，返回null让系统自动fold
            return action;
        }
    }
    
    /**
     * 脚本行动
     */
    public static class ScriptAction {
        private final String action;
        private final int amount;
        private final String reasoning;
        
        public ScriptAction(String action, int amount, String reasoning) {
            this.action = action;
            this.amount = amount;
            this.reasoning = reasoning;
        }
        
        public String getAction() { return action; }
        public int getAmount() { return amount; }
        public String getReasoning() { return reasoning; }
        
        @Override
        public String toString() {
            return action.toUpperCase() + (amount > 0 ? " " + amount : "") + " - " + reasoning;
        }
    }
}
